import React from 'react';
import { inject, observer } from 'mobx-react';
import { toJS } from 'mobx';
import { WeaDialog, WeaRightMenu, WeaLocaleProvider, WeaSearchGroup, WeaFormItem, WeaSelect, WeaDateGroup, WeaNewScroll, WeaBrowser, WeaTools, WeaPopoverHrm, WeaTop, WeaRadioGroup  } from "ecCom";
import { WeaTableNew } from "comsMobx";
import { Button, Spin, Row, message, Tooltip } from "antd";
const getLabel = WeaLocaleProvider.getLabel;
const WeaTable = WeaTableNew.WeaTable;
import * as Util from "../../../util/Util";
import AuthIndex from '../../task/taskexecl/AuthIndex'
@inject("goalBaseStore")
@observer
export default class GoalExport extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
          _height:Util.getCurrentHeight(),
          collectParams :{
            favname: getLabel(520928,"目标导出"),
            favouritetype: 5,
            link: '/spa/workrelate/static/index.html#/main/workrelate/goal/goalIndex?condtype=10',
            importantlevel: 1,
          },
          currentmenu:[{key: '0',icon: <i className='icon-coms-export' />,content: getLabel(17416,'导出'),onClick: key => this.doExportData()},
                      {key: '1',icon: <i className='icon-coms-Custom'/>,content : getLabel(32535,'显示列定制'),onClick : this.showColumn}],
          authVisiable:false
        }
      }

      componentWillMount() {//一些初始化请求
        Util.setWindowKeys(10,getLabel(520928,"目标导出"));
        const {goalBaseStore} = this.props;
        goalBaseStore.doInit();
      }

      showColumn = () => {//显示列定制
        const {goalBaseStore: { tableStore }} = this.props;
        tableStore.setColSetVisible(true);
        tableStore.tableColSet(true);
      }

      doExportData = () =>{
        const {goalExport} = this.props.goalBaseStore;
        goalExport();
      }

      getRightButton(ecId){
        const {hasRight,goalExport} = this.props.goalBaseStore;
        let menu = [];
        menu.push(<Tooltip ecId={`${ecId}_Tooltip@qh8poc@exportdata`} title={getLabel(17416,'导出')}><Button ecId={`${ecId}_Button@qm1d0a@exportdata`} type='primary' onClick={()=>goalExport()}>{getLabel(17416,'导出')}</Button></Tooltip>);
        if(hasRight){
          menu.push(<Tooltip ecId={`${ecId}_Tooltip@yplisb@authset`} title={getLabel(16526,'权限设置')}><Button ecId={`${ecId}_Button@m8m6m3@authset`} type='primary' onClick={()=>this.authVisable(true)}>{getLabel(16526,'权限设置')}</Button></Tooltip>);
        }
        return menu;
      }
      authVisable(flag){
        this.setState({authVisiable:flag});
      }
    //   getColumns = columns => {
    //     return columns.map(col => {
    //         if (col.dataIndex == "taskprogress") {
    //             return {
    //                 ...col,
    //                 render: (text, record, index) => {
    //                     return <WeaProgress percent={text || "0"} strokeColor={text == 100 ? "#68D358" : "#2DB7F5"}/>
    //                 }
    //             };
    //         }
    //         return col;
    //     });
    //   }
      render() {
        const {_height,collectParams,currentmenu,authVisiable} = this.state;
        const {loading,conditionInfo,updateRadioGroupParams,tableStore} = this.props.goalBaseStore;
        return (
          <div className="wea-workrelate-task-taskexport" style={{height:_height}}>
            <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@pqczf8`} spinning={loading}>
            <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@7ffnb9`}/>
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@t0x8mn`} datas={currentmenu} showUrlItem={false} style={{height:'100%'}} collectParams={collectParams}>
                <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@vgqsm6`}
                  title={getLabel(520928,"目标导出")}
                  icon={<i className='icon-coms-implement' />}
                  iconBgcolor='rgb(150, 53, 138)'
                  buttons = {this.getRightButton(this.props.ecId || '')}
                  showDropIcon={true}
                  dropMenuDatas = {currentmenu}/>
                <WeaRadioGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaRadioGroup@ob5nrr`} config={conditionInfo}  beforeInit={(a,b,c)=>{c(b);}}  onChange={(params)=> {updateRadioGroupParams(params);}}/>
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@32dzy1`}
                    comsWeaTableStore={tableStore}
                    hasOrder = {true}
                    // getColumns={this.getColumns}
                    needScroll = {true}/>
              </WeaRightMenu>
            {authVisiable &&<WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@u9oale`}
                icon="icon-coms-implement"
                iconBgcolor='rgb(150, 53, 138)'
                onCancel={() =>this.authVisable(false)}
                title={getLabel(16526, '权限设置')}
                visible={authVisiable}
                buttons={[<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@5y0mbf@$exportclose`} type="ghost" onClick={()=>this.authVisable(false)}>{getLabel(309, '关闭')}</Button>]}
                style={{ width: 900, height: 580 }}>
                <AuthIndex ecId={`${this && this.props && this.props.ecId || ''}_AuthIndex@hlldwm`} type="2"/>
            </WeaDialog>}
            </Spin>
          </div>
      )
    }
}